.include "asm/include/battle_commands.inc"

.data

_000:
    UpdateMonData OPCODE_SET, BATTLER_CATEGORY_ATTACKER, BMON_DATA_HP, 0
    UpdateVar OPCODE_SET, BSCRIPT_VAR_HP_CALC, 32767
    UpdateHealthBar BATTLER_CATEGORY_ATTACKER
    Call BATTLE_SUBSCRIPT_ATTACK_MESSAGE_AND_ANIMATION
    TryFaintMon BATTLER_CATEGORY_ATTACKER
    UpdateVar OPCODE_FLAG_OFF, BSCRIPT_VAR_BATTLE_STATUS, BATTLE_STATUS_FAINTED
    Call BATTLE_SUBSCRIPT_FAINT_MON
    UpdateVar OPCODE_FLAG_OFF, BSCRIPT_VAR_BATTLE_STATUS_2, BATTLE_STATUS2_EXP_GAIN
    Call BATTLE_SUBSCRIPT_GRANT_EXP

_026:
    TryReplaceFaintedMon BATTLER_CATEGORY_ATTACKER, TRUE, _087
    ShowParty 
    WaitMonSelection 
    SwitchAndUpdateMon BATTLER_CATEGORY_SWITCHED_MON
    PrintSendOutMessage BATTLER_CATEGORY_SWITCHED_MON
    Wait 
    PokemonSendOut BATTLER_CATEGORY_SWITCHED_MON
    WaitTime 72
    HealthbarSlideIn BATTLER_CATEGORY_SWITCHED_MON
    Wait 
    Call BATTLE_SUBSCRIPT_HAZARDS_CHECK
    CompareVarToValue OPCODE_FLAG_NOT, BSCRIPT_VAR_BATTLE_STATUS, BATTLE_STATUS_FAINTED, _065
    Call BATTLE_SUBSCRIPT_FAINT_MON
    UpdateVar OPCODE_FLAG_OFF, BSCRIPT_VAR_BATTLE_STATUS_2, BATTLE_STATUS2_EXP_GAIN
    Call BATTLE_SUBSCRIPT_GRANT_EXP
    TryReplaceFaintedMon BATTLER_CATEGORY_ATTACKER, TRUE, _087
    GoTo _026

_065:
    UpdateMonData OPCODE_SET, BATTLER_CATEGORY_ATTACKER, BMON_DATA_STATUS, STATUS_NONE
    SetHealthbarStatus BATTLER_CATEGORY_ATTACKER, BATTLE_ANIMATION_NONE
    UpdateMonDataFromVar OPCODE_GET, BATTLER_CATEGORY_ATTACKER, BMON_DATA_MAXHP, BSCRIPT_VAR_HP_CALC
    UpdateVarFromVar OPCODE_SET, BSCRIPT_VAR_MSG_BATTLER_TEMP, BSCRIPT_VAR_BATTLER_ATTACKER
    // The healing wish came true!
    BufferMessage 1005, TAG_NONE
    Call BATTLE_SUBSCRIPT_WISH_HEAL

_087:
    End 
